/*
* Conditions Of Use
*
* This software was developed by employees of the Sigmatrix(Beijing) Corporation.
* This software is provided by sigmatrix as a service and is expressly
* provided "AS IS."  Sigmatrix MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT
* AND DATA ACCURACY.  Sigmatrix does not warrant or make any representations
* regarding the use of the software or the results thereof, including but
* not limited to the correctness, accuracy, reliability or usefulness of
* the software.
*
* Permission to use this software is contingent upon your acceptance
* of the terms of this agreement.
*
*/
package com.sigmatrix.h5.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sigmatrix.h5.dao.DisRebateDao;
import com.sigmatrix.h5.entity.DisRebate;
import com.sigmatrix.h5.service.DisRebateService;
import com.sigmatrix.h5.utils.Assert;
import com.sigmatrix.sc.jdbc.common.service.ServiceImpl;

/**
 *@ClassName: DisRebateServiceImpl
 *@Description:
 *@author MH
 *@date 2017年8月16日 下午4:08:29
 */
@Service
public class DisRebateServiceImpl extends ServiceImpl<DisRebate,Integer> implements DisRebateService{
	@Autowired
	private DisRebateDao disRebateDao;
	@Override
	public List<DisRebate> findByStrategyIdAndDealerLevel(Integer strategyId, Short dealerLevel){
		final DisRebate vo = new DisRebate();
		vo.setDealerLevel(dealerLevel);
		vo.setStrategyId(strategyId);
		return select(vo);
	}
	public List<DisRebate> findByStrategyIdAndScanType(Integer strategyId,Short scanType){
		return disRebateDao.findByStrategyIdAndScanType(strategyId, scanType);
	}
	@Override
	public Map<String, DisRebate> judgeRebateAmountOfEachLevel(Integer strategyId,Short scanType) {
		Map<String,DisRebate> map = new HashMap<>();
		List<DisRebate> list = findByStrategyIdAndScanType(strategyId,scanType);
		Assert.notNull(list, String.format("返利策略没有明细{%s,%s}", strategyId,scanType));
		for (DisRebate disRebate : list) {
			map.put(disRebate.getDealerLevel()+""+
					disRebate.getRebateTarget()+""+
					disRebate.getRebateLevel(), disRebate);
		}
		return map;
	}

}
